<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<div class="line-big">
	<div class="xl1"></div>
	<div class="xl10">
		<div class="panel border-back" id="write_manager_info_div">
			<div class="panel-body text-center">
				<h1>
					<strong>添加管理员</strong>
				</h1>
			</div>
			<div class="panel-foot bg-white border-back" id="manager_permission">
				<div class="line-big ">
					<div class="xl6">
						<div class="label">
							<label for="managerName">*管理员用户名(2-25个字)</label>
						</div>
						<div class="field">
							<input type="text" class="input" id="managerName" value="${manager.managerName }" data-regex="^\S.{0,23}\S$" />
						</div>
					</div>
					<div class="xl6">
						<div class="label">
							<label for="managerPassword">*管理员密码(2-20个字)</label>
						</div>
						<div class="field">
							<input type="text" class="input" id="managerPassword" value="${manager.managerPassword }" data-regex="^\S.{0,18}\S$" />
						</div>
					</div>
				</div>
				<div class="line-big G-MarginTop20">
					<div class="xl6">
						<div class="label">
							<label for="managerEmail">*管理员邮箱(长度不超过50)</label>
						</div>
						<div class="field">
							<input type="text" class="input" id="managerEmail" value="${manager.managerEmail }" data-regex="^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$" />
						</div>
					</div>
					<div class="xl6">
						<div class="label">
							<label for="managerRealName">*管理员真实姓名(2-20个字)</label>
						</div>
						<div class="field">
							<input type="text" class="input" id="managerRealName" value="${manager.managerRealName }" data-regex="^\S.{0,18}\S$" />
						</div>
					</div>
				</div>

				<div class="line-big G-MarginTop20">
					<div class="xl12">
						<h4>
							<strong>分配权限</strong>
						</h4>
						<hr>
					</div>
					<div class="xl2">
						<label class="text-gray"> <input type="checkbox" id="begin_module" checked="checked" disabled="disabled" value="">开始
						</label>
					</div>
					<div class="xl2">
						<label> <input type="checkbox" id="type_module" value="">分类
						</label>
					</div>
					<div class="xl2">
						<label> <input type="checkbox" id="goods_module" value="">商品
						</label>
					</div>
					<div class="xl2">
						<label> <input type="checkbox" id="order_module" value="">订单
						</label>
					</div>
					<div class="xl2">
						<label> <input type="checkbox" id="order_return_module" value="">退换货
						</label>
					</div>
					<div class="xl2">
						<label> <input type="checkbox" id="shop_module" value="">店铺
						</label>
					</div>
				</div>
				<div class="line-big G-MarginTop10 G-MarginBottom10">
					<div class="xl2">
						<label> <input type="checkbox" id="coupon_module" value="">优惠券
						</label>
					</div>
					<div class="xl2">
						<label> <input type="checkbox" id="buyer_module" value="">买家
						</label>
					</div>
					<div class="xl2">
						<label> <input type="checkbox" id="message_module" value="">留言
						</label>
					</div>
					<div class="xl2">
						<label> <input type="checkbox" id="a_pic_module" value="">宣传图片
						</label>
					</div>
					<div class="xl2">
						<label> <input type="checkbox" id="help_module" value="">帮助中心
						</label>
					</div>
					<div class="xl2">
						<label> <input type="checkbox" id="manager_module" value="">管理员
						</label>
					</div>
				</div>


			</div>
			<div class="panel-foot bg-white">
				<div class="line-big">
					<div class="xl4"></div>
					<div class="xl4 text-center">
						<button class="button border-blue" id="submit_manager_button">提交管理员信息</button>
					</div>
					<div class="xl4"></div>
				</div>
			</div>
		</div>
		<div id="add_success_div" class="G-MarginTop100" style="display: none;">
			<div class="line-big">
				<div class="xl3"></div>
				<div class="xl6 text-center">
					<h1 class="text-center">
						<span class="icon-check-circle text-yellow"></span> 添加管理员成功了。
					</h1>
					<br />
					<p>
						<button class="button bg-blue" id="go_on_add_manager">
							<span class="icon-plus-circle"></span> 继续添加管理员
						</button>
						<button class="button bg-green click_go_to_nav_button" data-trigger-id="#sub_see_manager_list">
							<span class="icon-eye"></span> 查看所有管理员
						</button>
					</p>
				</div>
				<div class="xl3"></div>
			</div>
		</div>
	</div>
	<div class="xl1"></div>
</div>
<div style="display: none" id="time_temp_div"></div>
<!-- pintuer -->
<script type="text/javascript" src="js/pintuer.js"></script>
<script type="text/javascript">
	$(function()
	{
		var myDate = new Date();
		$("#time_temp_div").html(myDate.getHours() + "-" + myDate.getMinutes() + "-" + myDate.getSeconds() + "-" + myDate.getMilliseconds());

		$("#submit_manager_button").click(function()
		{
			var managerName = $("#managerName").val();
			var managerPassword = $("#managerPassword").val();
			var managerEmail = $("#managerEmail").val();
			var managerRealName = $("#managerRealName").val();

			if (managerName.length <= 0 || managerPassword.length <= 0 || managerEmail.length <= 0 || managerRealName.length <= 0)
			{
				alert("标有*的输入项都是必填项.")
				return false;
			}

			var tips = "";
			var tips_number = 1;
			$.each([ $("#managerName"), $("#managerPassword"), $("#managerEmail"), $("#managerRealName") ], function(i, n)
			{
				if (new RegExp(n.attr("data-regex")).test(n.val()) == false)
				{
					tips += tips_number++ + " . \"" + n.val() + "\" 不满足输入要求;\n";
				}
			});
			if (tips.length > 0)
			{
				alert(tips + "\n请检查一下重新输入.");
				return false;
			}

			var moduleNamesArray = new Array();
			var moduleCheckedArray = new Array();
			$("#manager_permission input[type='checkbox']").each(function()
			{
				moduleNamesArray.push($(this).attr("id"));
				moduleCheckedArray.push($(this).is(":checked") ? "1" : "0");
			});

			var submit_manager_button_html = $("#submit_manager_button").html();
			$.ajax(
			{
				url : "admin/m_add_manager_do",
				type : "POST",
				dataType : "json",
				traditional : true,
				beforeSend : function(XMLHttpRequest)
				{
					$("#submit_manager_button").attr("disabled", "disabled");
					$("#submit_manager_button").html("正在提交管理员信息中...");
				},
				data :
				{
					'manager.managerName' : managerName,
					'manager.managerPassword' : managerPassword,
					'manager.managerEmail' : managerEmail,
					'manager.managerRealName' : managerRealName,
					'moduleNamesArray' : moduleNamesArray,
					'moduleCheckedArray' : moduleCheckedArray
				},
				success : function(json, textStatus)
				{
					if (json.success == true)
					{
						$("#write_manager_info_div").slideUp();
						$("#add_success_div").slideDown(function()
						{
							$(".admin").animate(
							{
								scrollTop : 0
							}, 0);
						});

					}
					else
					{
						alert(json.info);
					}
				},
				error : function(XMLHttpRequest, textStatus, errorThrown)
				{
					alert("提交失败，请仔细检查您的输入是否满足要求。");
				},
				complete : function(XMLHttpRequest, textStatus)
				{
					$("#submit_manager_button").removeAttr("disabled");
					$("#submit_manager_button").html(submit_manager_button_html);
				}
			});
		});

		$("#go_on_add_manager").click(function()
		{
			$("#add_success_div").slideUp();
			$("#write_manager_info_div").slideDown(function()
			{
				$("#managerName").val("");
				$("#managerPassword").val("");
				$("#managerEmail").val("");
				$("#managerRealName").val("");
			});
		});

	});
</script>